from django import forms
from django.forms import widgets as ws

from apps.steps.models import Steps
from apps.interface.models import Interface


class StepModelForm(forms.ModelForm):

    class Meta:
        model = Steps
        fields = '__all__'
        exclude = ['case', 'creator', 'add_time', 'edit_time']
        label = {
            'name': '名称',
            'type': '类型',
            'interface': '接口',
            'params': '参数',
            'expect': '期望',
            'return_values': '返回值',
            'doc': '描述'
        }
        widgets = {
            "name": ws.TextInput(attrs={"class": "form-control"}),
            "type": ws.Select(attrs={
                "class": "selectpicker bla bli form-control", "data-live-search": 'true', 'style': 'display: none'
            }),
            "keyword": ws.Select(attrs={
                "class": "selectpicker bla bli form-control", "data-live-search": 'true', 'style': 'display: none'
            }),
            "doc": ws.TextInput(attrs={"class": "form-control"})
        }
        error_messages = {
            "name": {"required": '项目名称不能为空', 'invalid': '请输入正确的测试名称'}
        }

    def __init__(self, *args, **kwargs):
        super(StepModelForm, self).__init__(*args, **kwargs)
        self.fields['keyword'].widget.choices = Interface.objects.values_list('id', 'name')
